from likeshop_api_project.api.get_an_adress import get_an_address
from likeshop_api_project.api.login_api import login_model
from likeshop_api_project.base.mybase import Tools
from likeshop_api_project.api.get_user_address import get_user_address_model
import random

# 删除收货地址
class del_address_model(Tools):
    path = '/api/user_address/del'

    def get_random_address_id(self, hd):
        address_lists = get_user_address_model(self.huihua).get_user_address_action(hd)
        print(address_lists)
        return random.choice(address_lists['data'])['id']


    def del_address_action(self, id, hd):
        del_address_data = {
            "id": id
        }
        del_address = self.huihua.post(url=self.hosturl+self.path, data=del_address_data, headers=hd)
        return del_address.json()



if __name__ == '__main__':
    import requests

    s = requests.session()
    reg = login_model(huihua=s)
    msg = reg.login_action(account="13356786546", password="rr98765", client=2)
    # print(msg)
    get_token = msg["data"]["token"]
    # print(get_token)
    hd = {"token": get_token}

    del_address = del_address_model(huihua=s)
    random_id = get_an_address.get_random_address_id(hd=hd)
    msg = del_address.del_address_action(id=random_id, hd=hd)
    print(msg)
